--POUR CONTROLE



define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_cli_sectcial AS (SELECT * FROM &erp.cli_sectcial WHERE 1=2);


DELETE FROM se_cli_sectcial;


 INSERT INTO se_cli_sectcial
 (SELECT id sectcial_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle sectcial_lib,
         NULL sectcial_lib2
    FROM uv_csecteurs) ;

 UPDATE se_cli_sectcial tf SET enreg_id=(select enreg_id FROM &erp.cli_sectcial f WHERE f.sectcial_cod=tf.sectcial_cod) ;
 UPDATE se_cli_sectcial tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('sectcial_cod','CLI_SECTCIAL','O') ;

 commit;


select * from (
SELECT &outils.stragg(source) source,sectcial_cod, enreg_id, enreg_s, sectcial_lib, sectcial_lib2
FROM (
  SELECT 'uv' source ,g.* FROM se_cli_sectcial g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.cli_sectcial g
  )
GROUP BY sectcial_cod, enreg_id, enreg_s, sectcial_lib, sectcial_lib2
HAVING Count(1)!=2) r
ORDER BY sectcial_cod;